package com.binfenhulian.chinaenergy.ces.utils.collections;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by wanghjbuf on 2018/3/10.
 */
public class ListUtils {

    /**
     * 固定长度分割list
     * @param list
     * @param sizeLimit
     * @return
     */
    public static List<List<?>> splitList(List<?> list , int sizeLimit) {
        List<List<?>> resultList = new ArrayList<List<?>>();
        int size = list.size();
        int num = size%sizeLimit==0?size/sizeLimit:(size/sizeLimit+1);

        int start = 0;
        int end = 0;
        for(int i=1;i<=num;i++) {
            start = (i-1)*sizeLimit;
            end = i*sizeLimit>size ?size : i*sizeLimit;
            resultList.add(list.subList(start, end));
        }
        return resultList;
    }
}
